/* eslint-disable import/no-anonymous-default-export */
// const debounceFunc = (delay) => {
//   let timer;
//   return function (value,callback) {
//     clearTimeout(timer);
//     timer = setTimeout(function () {
//       callback(value)
//     }, delay);
//   };
// };
// export const debounce = debounceFunc(500);

// 防抖函数
export const debounce = (callback, delay) => {
  let timer
  return function (arg) {
    clearTimeout(timer)
    timer = setTimeout(function () {
      callback(arg)
    }, delay)
  }
}

// 节流
export const throttle = (callback, wait, flag) => {
  let timerOut
  return function () {
    if (flag) {
      return
    }
    if (!timerOut) {
      timerOut = setTimeout(function () {
        timerOut = null
        callback()
      }, wait)
    }
  }
}